<?php
class UserModel{
	
	private $id,$login,$mdp;
	
	public function getId()
	{
		return $this->id;
	}
	
	public function getLogin()
	{
		return $this->login;
	}
	
	public function getMdp()
	{
		return $this->mdp;
	}
	
	public function setId($value)
	{
		$this->id = $value;
	}
	
	public function setLogin($value)
	{
		$this->login = $value;
	}
	
	public function setMdp($value)
	{
		$this->mdp = $value;
	}
	
	public function connexion_valide($user,$mdp)
	{
		$sql = " SELECT idUtilisateur,login,password FROM utilisateur WHERE login='$user' && password='$mdp'";
		$req = mysql_query($sql);
		$nb_res = mysql_num_rows($req);
		$row = mysql_fetch_array($req);
		
		if($nb_res != 0)
		{
			$this->setId($row["idUtilisateur"]);
			$this->setLogin($row["login"]);
			$this->setMdp($row["password"]);
			return 1;
		}
		else
		{
			return 0;
		}
		
	}
	
	public function getUser($idUser)
	{
		$sql = "SELECT login FROM utilisateur WHERE idUtilisateur ='$idUser'";
		$req = mysql_query($sql);
		$row = mysql_fetch_array($req);
		$user = $row["login"];
		
		return $user;
		
	}
	
	public function getUsers()
	{
		$sql = "SELECT * FROM utilisateur";
		$req = mysql_query($sql);
		$i = 0;
		while($row = mysql_fetch_array($req))
		{
			$tab_user[$i]["id"] = $row["idUtilisateur"];
			$tab_user[$i]["login"] = $row["login"];
			$tab_user[$i]["nom"] = $row["nom"];
			$tab_user[$i]["prenom"] = $row["prenom"];
			$tab_user[$i]["mail"] = $row["mail"];
			
			if($row["idStatut"] == 1)
			{
				$statut = "Administrateur";
			}
			else
			{
				$statut = "Simple utilisateur";
			}
			$tab_user[$i]["statut"] = $statut;
			$i++;
		}
		
		return $tab_user;
	}
	
	public function deleteUtilisateur($id_user)
	{
		$sql = "DELETE FROM utilisateur WHERE idUtilisateur='".$id_user."' ";
		$req = mysql_query($sql);
		if($req)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public function getStatut($id_user)
	{
		$sql = "SELECT idStatut FROM utilisateur WHERE idUtilisateur='".$id_user."'";
		$req = mysql_query($sql);
		$row = mysql_fetch_array($req);
		$statut = $row["idStatut"];
		
		return $statut;
	}
}

?>